package com.wnxy.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wnxy.bean.Goods;
import com.wnxy.bean.GoodsDTO;
import com.wnxy.bean.GoodsDetail;
import com.wnxy.mapper.GoodsMapper;
import com.wnxy.service.IGoodsDetailService;
import com.wnxy.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements IGoodsService {

    @Autowired
    private IGoodsDetailService goodsDetailService;

    @Override
    public List<GoodsDTO> queryGoodsDetail() {
        return baseMapper.queryGoodsDetail();
    }

    @Override
    public void saveGoods(GoodsDTO goodsDTO) {
        Goods goods = BeanUtil.copyProperties(goodsDTO, Goods.class);
        baseMapper.insert(goods);

        GoodsDetail goodsDetail = new GoodsDetail();
        goodsDetail.setGoodsId(goods.getGoodsId());
        goodsDetail.setDescription(goodsDTO.getDescription());
        goodsDetail.setBrandId(goodsDTO.getBrandId());
        goodsDetailService.save(goodsDetail);
    }
}
